package com.aceitunaproject.webclient.client;

import com.aceitunaproject.shared.gamelement.Installation;
import com.aceitunaproject.shared.gamelement.Settlement;
import com.aceitunaproject.shared.gamelement.Unit;
import com.google.gwt.dom.client.ImageElement;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ElementDetails extends VerticalPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Unit theUnit;

	public ElementDetails() {

	}

	public void setUnit(Unit unit) {

		this.clear();
		theUnit = unit;
		addLabel("Unit :");
		addLabel("unit", unit.getName());
		addLabel("Time Units :" + unit.getTimeUnits());
		addLabel("Player :" + unit.getPlayer().getName());
		addLabel("Persons:" + unit.getPersons());

	}

	public void setInstallation(Installation installation) {
		this.clear();
		addLabel("Installation :");
		addLabel("Installation", installation.getName());
		addLabel("Type :" + installation.getType());
		addLabel("Player :" + installation.getPlayer().getName());

	}

	public void setSettlement(Settlement settlement) {
		this.clear();
		addLabel("Settlement :");
		addLabel("settlement", settlement.getName());
		addLabel("Population :" + settlement.getPersons());
		addLabel("Player :" + settlement.getPlayer().getName());

	}

	private void addLabel(String text) {
		this.add(new Label(text));
	}

	private void addLabel(String imageName, String text) {

		Label label = new Label(text);
		ImageElement image = new BoardImageProvider()
				.getThingImage(new WebThing(imageName));
		label.getElement().insertFirst(image);
		this.add(label);

	}

	public Unit getSelectedUnit() {
		return theUnit;
	}
}
